package HomeWork_java03;

import java.util.Arrays;

public class QuickTwo {
	public static void main(String[] args) {
		int [] a={5,3,7,2,9,8,1,4};
		Quick02(a,0,a.length-1);
		System.out.println(Arrays.toString(a));
	}
	public static void Quick02(int[] a,int l,int h){
		if(l>=h){
			return ; 
		}
		int p=Quick(a,l,h);
		Quick(a,l,h);
		Quick02(a,l,p-1);
		Quick02(a,p+1,h);
		
	}
	public static int Quick(int [] a,int l, int h){
		int pv=a[l],b=l;
		for(int i=0;b<=h;i++){
			if(a[h]<pv){
				b++;
			}else{
				h--;
			}
			if(a[b]>pv){
				swap(a,b,h);
				System.out.println(Arrays.toString(a));
			}
			if(b==h){
				swap(a,l,h);
				System.out.println(Arrays.toString(a));
			}
		}
		return b;
		
	}

	public static void swap(int[] a, int i, int j) {
		int t=0;
		t=a[i];
		a[i]=a[j];
		a[j]=t;
		
	}

}
